//
//  BCWalletExchangeDirectionView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2019/1/21.
//  Copyright © 2019 guoshikeji. All rights reserved.
//

#import "BCWalletExchangeDirectionView.h"

//
#import "UserWalletExchangeResponse.h"

@implementation BCWalletExchangeDirectionButton

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setTitleColor:[UIColor qmui_colorWithHexString:@"#000000"] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
        //
        [self setupSubviews];
    }
    return self;
}
- (void)setupSubviews {
    self.moreButton = [QMUIButton new];
    [self.moreButton setImage:LOAD_IMAGE(@"wallet_exchange_cur_more") forState:UIControlStateNormal];
    [self addSubview:self.moreButton];
    [self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-20.0*MIN(WidthScale, 1));
        make.centerY.mas_equalTo(self);
    }];
    self.moreButton.userInteractionEnabled = false;
}

@end

@interface BCWalletExchangeDirectionView ()

@property (nonatomic, strong) UIView *changeButtonContentView;


/**
 *sepLine
 */
@property (nonatomic, strong) UIView *sepLine;

@end

@implementation BCWalletExchangeDirectionView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor qmui_colorWithHexString:@"#F6F5FA"];
        [self setupSubviews];
    }
    return self;
}
- (void)setupSubviews {
    self.changeButtonContentView = [UIView new];
    [self addSubview:self.changeButtonContentView];
    [self.changeButtonContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self);
        make.height.mas_equalTo(self);
        make.width.mas_equalTo(self.changeButtonContentView.mas_height).multipliedBy(68.0/89.0);
    }];
    self.changeButtonContentView.clipsToBounds = true;
    self.changeButton = [QMUIButton new];
    [self.changeButton setImage:LOAD_IMAGE(@"wallet_exchange_cur_btn") forState:UIControlStateNormal];
    self.changeButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.changeButtonContentView addSubview:self.changeButton];
    [self.changeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.changeButtonContentView);
    }];
    //
    self.fromButton = [BCWalletExchangeDirectionButton new];
    [self addSubview:self.fromButton];
    [self.fromButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(self);
        make.right.mas_equalTo(self.changeButtonContentView.mas_left);
        make.height.mas_equalTo(self).multipliedBy(.5);
    }];
    self.toButton = [BCWalletExchangeDirectionButton new];
    [self addSubview:self.toButton];
    [self.toButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(self);
        make.right.mas_equalTo(self.fromButton);
        make.height.mas_equalTo(self).multipliedBy(.5);
    }];
    
    //
    [self setFromToLabels];
    //
    self.sepLine = [UIView new];
    self.sepLine.backgroundColor = [UIColor qmui_colorWithHexString:@"#E7E7E9"];
    [self addSubview:self.sepLine];
    [self.sepLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self.changeButtonContentView.mas_left);
        make.height.mas_equalTo(1.0);
        make.centerY.mas_equalTo(self);
    }];
}
//
- (void)setFromToLabels {
    self.fromLabel = [QMUILabel new];
    [self addSubview:self.fromLabel];
    //
    self.toLabel = [QMUILabel new];
    [self addSubview:self.toLabel];
    //
    self.fromLabel.textColor = self.toLabel.textColor = [UIColor qmui_colorWithHexString:@"#9B9B9B"];
    self.fromLabel.font = self.toLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
    //
    [self.fromLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(20.0*MIN(WidthScale, 1.0));
        make.top.mas_equalTo(self);
        make.height.mas_equalTo(self).multipliedBy(.5);
    }];
    [self.toLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.fromLabel);
        make.height.mas_equalTo(self).multipliedBy(.5);
        make.bottom.mas_equalTo(self);
    }];
}

//
- (void)setExchangeData:(UserWalletExchangeData *)exchangeData {
    _exchangeData = exchangeData;
    //
    self.fromLabel.text = exchangeData.flow.from;
    self.toLabel.text = exchangeData.flow.reach;
    //
    self.fromButton.moreButton.alpha = self.toButton.moreButton.alpha = exchangeData.data.count>2?1:0;
    self.fromButton.userInteractionEnabled = self.toButton.userInteractionEnabled = exchangeData.data.count>2?true:false;
}

- (void)setDataModel:(BCWalletExchangeDataModel *)dataModel {
    _dataModel = dataModel;
    //
    if (dataModel.fromCurrency) {
        [self.fromButton setTitle:dataModel.fromCurrency.acronyms forState:UIControlStateNormal];
    }
    if (dataModel.toCurrency) {
        [self.toButton setTitle:dataModel.toCurrency.acronyms forState:UIControlStateNormal];
    }
}

+ (CGFloat)defaultHeight {
    return 90.0;
}

@end
